package cn.itcast.demo.controller;

import cn.itcast.demo.pojo.User;
import cn.itcast.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("hello")
public class HelloController {

    @Autowired
    private UserService userService;


    /**
     *
     * 根据用户id查询用户信息
     * @param userId
     * @return
     */
    @GetMapping("user/{id}")
    @ResponseBody
    public User queryUserById(@PathVariable("id")Long userId){
        User user = this.userService.queryUserById(userId);

        if (user != null) {
            return user;
        }

        return null;
    }
}
